import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Scanner;

public class Demo {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		hourRest();
	}

	/**
	 * 写程序，要求输入预期寿命如85岁，输入出生年月日，然后输出你还能活多少小时？
	 * 
	 * @return
	 */
	public static void hourRest() {
		SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
		Scanner input = new Scanner(System.in);
		String birthday;
		int lifeSpan;
		Date date = new Date();
		Calendar calendar = Calendar.getInstance();
		Calendar calendarDie = Calendar.getInstance();
		System.out.println("请输入预期寿命：");
		lifeSpan = input.nextInt();
		System.out.println("请以2000-01-01格式输入出生年月日：");
		birthday = input.next();
		try {
			date = dft.parse(birthday);
		} catch (ParseException px) {
			System.out.println("日期格式输入错误！");
			System.exit(0);
		}
		calendarDie.setTime(date);
		calendarDie.add(Calendar.YEAR, lifeSpan);
		long ret = calendarDie.getTimeInMillis() - calendar.getTimeInMillis();
		System.out.println(dft.format(calendarDie.getTime()));
		long y = ret / 1000 / 60 / 60 / 24 / 365;
		long d = ret / 1000 / 60 / 60 / 24 % 365;
		long h = ret / 1000 / 60 / 60 % 24;
		long m = ret / 1000 / 60 % 60;
		System.out.println(String.format("%d年%d天%d小时%d分", y, d, h, m));
	}

	public static void demoJSON() {
		Book book = new Book(1001, "唐诗三百首", 15.8);
		Book book1 = new Book(1002, "新365夜好故事", 18.8);
		List<Book> list = new ArrayList<Book>();
		list.add(book);
		list.add(book1);
		String string = BookJsonHelper.toJSON(book);
		System.out.println(string);
		System.out.println(BookJsonHelper.toBook(string).toString());
		System.out.println(BookJsonHelper.toJSON(list));
	}

	public static void string1() {
		System.out.println(StringHelper.randomNumberString(5));
	}

	public static void string2() {
		System.out.println(StringHelper.randomCharString(10));
	}

	public static void string3() {
		System.out.println(StringHelper.randomCharAndNumberString(10));
	}

	public static void string4() {
		System.out.println(StringHelper.convertToChinese(-124214));
	}

	public static void string5() {
		System.out.println(StringHelper
				.indexOf("abcadeffegbcdeabcefw", "bc", 4));
	}

	public static void string6() {
		System.out.println(StringHelper.lastIndexOf("abcadeffegbcdeabcefw",
				"bc", 2));
	}

	public static void string7() {
		System.out.println(StringHelper.getFileExtName("dsfhgfd.jpg"));
		System.out.println(StringHelper.getFileExtName("dsfhgfd."));
	}

	public static void string8() {
		System.out.println(StringHelper.length("dsfhgfd187", CharType.CHAR));
		System.out.println(StringHelper.length("dsfhgfd187",
				CharType.NotCharAndNumber));
	}
}
